﻿using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using System.IO;
using System.Web.UI.WebControls.WebParts;


public partial class ReportDashboard : System.Web.UI.Page
{

    Guid gudUserID = CommonUtility.GetLoggedOnUserId();


    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            GetData();
            //GetAssesser();
            //GetAuditor();
            //GetIndustry();
        }
        

    }

    private DataSet GetDataSet()
    {
        DataSet objDs = null;
        try
        {
            objDs = new CandidateWorkflowBAL().GetAssessorStatus();
            //CommonUtility.ConvertDateyyyymmdd(txtDateFrom.Text), CommonUtility.ConvertDateyyyymmdd(txtDateUpto.Text), 1
            //btnDownload.Visible = false;
            //if (objDs != null)
            //{
            //    if (objDs.Tables.Count > 0)
            //    {
            //        if (objDs.Tables[0].Rows.Count > 0)
            //        {
            //            btnDownload.Visible = true;
            //        }
            //    }
            //}
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = "Error : " + ex.Message;
            ex.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;


    }
    public DataSetAssessor GetAttendanceChartDataset()
    {
        DataSet objDS = new DataSet();

        DataSetAssessor dsCustomers = new DataSetAssessor();
        DataTable objDt =new CandidateWorkflowBAL().GetAssessorStatus().Tables[0];
        //CommonUtility.ConvertDateyyyymmdd(txtDateFrom.Text), CommonUtility.ConvertDateyyyymmdd(txtDateUpto.Text), 1
        DataTableReader reader = new DataTableReader(objDt);
        dsCustomers.Tables["dsCustomers"].Load(reader);
        return dsCustomers;
    }
    public AuditorDataSet GetAuditorChartDataset()
    {
        DataSet objDS = new DataSet();

        AuditorDataSet dsAuditor = new AuditorDataSet();
        DataTable objDt = new CandidateWorkflowBAL().GetAuditorStatus().Tables[0];
        //CommonUtility.ConvertDateyyyymmdd(txtDateFrom.Text), CommonUtility.ConvertDateyyyymmdd(txtDateUpto.Text), 1
        DataTableReader reader = new DataTableReader(objDt);
        dsAuditor.Tables["dsAuditor"].Load(reader);
        return dsAuditor;
    }
    public IndustryDataSet GetIndustryChartDataset()
    {
        DataSet objDS = new DataSet();

        IndustryDataSet dsIndustry = new IndustryDataSet();
        DataTable objDt = new CandidateWorkflowBAL().GetIndustryStatus().Tables[0];
        //CommonUtility.ConvertDateyyyymmdd(txtDateFrom.Text), CommonUtility.ConvertDateyyyymmdd(txtDateUpto.Text), 1
        DataTableReader reader = new DataTableReader(objDt);
        dsIndustry.Tables["dsIndustry"].Load(reader);
        return dsIndustry;
    }
    
    private void GetData(params object[] param)
    {
        try
        {
            rvBar.LocalReport.ReportPath = Server.MapPath("~/report/AssessorStatus.rdlc");
            rvBar.LocalReport.EnableHyperlinks = true;

            DataSetAssessor dsBar = GetAttendanceChartDataset();
            ReportDataSource dsorBar = new ReportDataSource("DataSet1", dsBar.Tables[0]);

            AuditorDataSet dsMap = GetAuditorChartDataset();
            ReportDataSource dsorMap = new ReportDataSource("DataSet2", dsMap.Tables[0]);

            IndustryDataSet dsAttendance = GetIndustryChartDataset();
            ReportDataSource dsorAtt = new ReportDataSource("DataSet3", dsAttendance.Tables[0]);

            rvBar.LocalReport.DataSources.Clear();
            rvBar.LocalReport.MapTileServerConfiguration.AppID = "AqCUTlVe8ueM3yJotaLUxSYK_hpVYx4NMkNYKwY0FhNYjIZc4Q0HjVyBt0dj-O3t";
            rvBar.LocalReport.DataSources.Add(dsorBar);
            rvBar.LocalReport.DataSources.Add(dsorMap);
            rvBar.LocalReport.DataSources.Add(dsorAtt);


            lblErrorMessage.Text = string.Empty;
            //rvMap.ProcessingMode = ProcessingMode.Local;
            rvBar.ShowToolBar = true;
            
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = "Error : " + ex.Message;
        }
        
    }

     
           
    protected void btn_download_Click(object sender, EventArgs e)
    {
        string filePath = ConfigurationManager.AppSettings["filePathExcel"];
        string parameter = null;
        string DATESTRINGFORMAT = "dd-MM-yyyy_HH-mm-ss";
        string SAMPLEFILENAME = "CandidateWorkFlow.xls";
        String ServerFileFolderPath = "";
        string Filename = SAMPLEFILENAME.Replace(".xls", "_" + "__" + DateTime.Now.ToString(DATESTRINGFORMAT)) + ".xls";
        try
        {
            DataSet objDs = new DataSet();
            objDs = GetDataSet();

            //CommonUtility.ErrorLog_Report("Candidate Work Flow", CommonUtility.GetLoggedOnUserId(), CommonUtility.GetLoggedOnUserName(), Filename, parameter);

            String SavedFileFolderPath = filePath + SAMPLEFILENAME.Replace(".xls", "_" + "__" + DateTime.Now.ToString(DATESTRINGFORMAT)) + ".xls";
            ServerFileFolderPath = Server.MapPath(SavedFileFolderPath);
            CommonUtility.ExportToExcel_Sheet(objDs, ServerFileFolderPath);
        }
    
        catch (Exception ex)
        {
            lblErrorMessage.Text = "Error : " + ex.Message;
        }
       
    }

    //private DataSet GetAssesser()
    //{

    //    DataSet objDs = null;
    //    try
    //    {
    //        objDs = new CandidateWorkflowBAL().GetAssessorStatus();
    //        gvAssessor.DataSource = objDs;
    //        gvAssessor.DataBind();
    //    }
    //    catch (Exception ex)
    //    {
    //        lblErrorMessage.Text = "Error : " + ex.Message;
    //        ex.AddErrorToLog(); //throw new ApplicationException(exception.Message);
    //    }
    //    return objDs;
    //}
    //private DataSet GetAuditor()
    //{

    //    DataSet objDs = null;
    //    try
    //    {
    //        objDs = new CandidateWorkflowBAL().GetAuditorStatus();
    //        gvAuditor.DataSource = objDs;
    //        gvAuditor.DataBind();
    //    }
    //    catch (Exception ex)
    //    {
    //        lblErrorMessage.Text = "Error : " + ex.Message;
    //        ex.AddErrorToLog(); //throw new ApplicationException(exception.Message);
    //    }
    //    return objDs;
    //}
    //private DataSet GetIndustry()
    //{

    //    DataSet objDs = null;
    //    try
    //    {
    //        objDs = new CandidateWorkflowBAL().GetIndustryStatus();
    //        gvIndustry.DataSource = objDs;
    //        gvIndustry.DataBind();
    //    }
    //    catch (Exception ex)
    //    {
    //        lblErrorMessage.Text = "Error : " + ex.Message;
    //        ex.AddErrorToLog(); //throw new ApplicationException(exception.Message);
    //    }
    //    return objDs;
    //}
}
